//
//  RCTicketFlyOrderCell.m
//  RocketProject
//
//  Created by Wu Chengwei on 13-11-29.
//  Copyright (c) 2013年 Rocket. All rights reserved.
//

#import "RCTicketFlyOrderCell.h"

#import "CommonDefines.h"
#import "UIColor-Expanded.h"
#import "TTTAttributedLabel.h"
#import "RCTrainOrderDetailInfoDataModel.h"
#import "NSString+NSString_Ex_.h"

#define kLineImageFile          @"image_line_type3.png"
#define kBGImageFile            @"image_discount_cell_bg.png"
#define kArrowImageFile         @"flyTicket_orderCell_arrow.png"


@implementation RCTicketFlyOrderTimeHeaderCell {
    UIImageView *_bgGroundView;
    UIImageView *_typeImageView;
    
    UILabel *_startTime;
    
    UILabel *_trafficTypeLabel;
    UIImageView *_airPlaneDotImageView;
    UILabel     *_airTypeLabel;
    UIImageView *_lineImageView;
    UIImageView *_flyCodeImageView;
    UILabel     *_flyCodeLabel;
}

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
        
        UIImage *bgImage = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:kBGImageFile ofType:nil]];
        [self setBackgroundColorWithImage:bgImage];
        
        
        [self createPlaceHolder];
        self.backgroundColor = [UIColor clearColor];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return self;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

- (void) createPlaceHolder
{
    _bgGroundView = [[UIImageView alloc] initWithFrame:CGRectMake(14, 13, 292, 35)];
    [self.contentView addSubview:_bgGroundView];
    _bgGroundView.image = [UIImage imageNamed:@"icon_ticketType_bg"];
    [_bgGroundView release];
    
    _typeImageView = [[UIImageView alloc] initWithFrame:CGRectMake(32, 23, 16, 14)];
    [self.contentView addSubview:_typeImageView];
    _typeImageView.image = [UIImage imageNamed:@"icon_ticketType_fly_white"];
    [_typeImageView release];
    
    _startTime = [[UILabel alloc] initWithFrame:CGRectMake(65, 23, 240, 15)];
    _startTime.font = [UIFont fontWithName:kFontNameHelvetica size:15];
    _startTime.backgroundColor = [UIColor clearColor];
    _startTime.textColor = [UIColor whiteColor];
    [self.contentView addSubview:_startTime];
    [_startTime release];
    
    _airPlaneDotImageView = [[UIImageView alloc]initWithFrame:CGRectMake(33, 58, 10, 10)];
    _airPlaneDotImageView.backgroundColor = [UIColor clearColor];
    [_airPlaneDotImageView setImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"icon_flyCompanyLogo.png" ofType:nil]]];
    [self.contentView addSubview:_airPlaneDotImageView];
    [_airPlaneDotImageView release];
    
    _trafficTypeLabel = [[UILabel alloc] initWithFrame:CGRectMake(48, 58, 120, 14)];
    _trafficTypeLabel.font = [UIFont fontWithName:kFontNameHeiti size:14];
    _trafficTypeLabel.backgroundColor = [UIColor clearColor];
    _trafficTypeLabel.textColor = [UIColor colorWithHex:0xff333333];
    [self.contentView addSubview:_trafficTypeLabel];
    [_trafficTypeLabel release];
    
    
    _airTypeLabel = [[UILabel alloc]initWithFrame:CGRectMake(180, 58, 70, 14)];
    _airTypeLabel.font = [UIFont fontWithName:kFontNameHeiti size:14];
    _airTypeLabel.backgroundColor = [UIColor clearColor];
    _airTypeLabel.textColor = kNormalHeadTextColor;
    [self.contentView addSubview:_airTypeLabel];
    [_airTypeLabel release];
    
    _flyCodeImageView = [[UIImageView alloc]initWithFrame:CGRectMake(258, 50, 48, 28)];
    _flyCodeImageView.backgroundColor = [UIColor clearColor];
    [_flyCodeImageView setImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"flyTicket_formBG_flylabel_upper.png" ofType:nil]]];
    
    _flyCodeLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 8, 48, 12)];
    _flyCodeLabel.backgroundColor = [UIColor clearColor];
    _flyCodeLabel.font = [UIFont fontWithName:kFontNameLightHeiti size:12];
    _flyCodeLabel.textColor = kNormalTextColor;
    _flyCodeLabel.textAlignment = UITextAlignmentCenter;
    [_flyCodeImageView addSubview:_flyCodeLabel];
    [_flyCodeLabel release];
    
    [self.contentView addSubview:_flyCodeImageView];
    [_flyCodeImageView release];
    
    _lineImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 81, 320, 1)];
    _lineImageView.backgroundColor = [UIColor clearColor];
    [_lineImageView setImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:kLineImageFile ofType:nil]]];
    [self.contentView addSubview:_lineImageView];
    [_lineImageView release];
    
}


- (void) bindData:(RCFlyOrderItemInfo *)dataModel
{
    if (nil == dataModel) {
        return;
    }
    _startTime.text = [NSString stringWithFormat:@"%@%@-%@",dataModel.startDate,dataModel.startCity,dataModel.endCity];
    _trafficTypeLabel.text = [NSString stringWithFormat:@"%@ %@",dataModel.airCompany,dataModel.airName];
    _airTypeLabel.text = dataModel.flyType;
    
    _flyCodeLabel.text = dataModel.airTypeName;
}

+(CGFloat)getCellHeight{
    return 82;
}

@end




@implementation RCTicketFlyTimePriceDetailCell{
    UILabel *_startTime;
    UILabel *_endTime;
    
    UILabel *_startAddr;
    UILabel *_endAddr;
    
    UILabel *_priceLabel;
    UILabel *_priceLabelContent;
    
    UILabel *_orginPriceLabel;
    UILabel *_orginPriceLabelContent;
    
    UILabel *_feeLabel;
    UILabel *_feeLabelContent;
    
    UIImageView *_lineImageView;
    
}

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
        UIImage *bgImage = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:kBGImageFile ofType:nil]];
        [self setBackgroundColorWithImage:bgImage];
        self.backgroundColor = [UIColor clearColor];
        [self createPlaceHolder];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return self;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

- (void) createPlaceHolder
{
    //出发时间
    _startTime = [[UILabel alloc] initWithFrame:CGRectMake(33, 8, 70, 14)];
    _startTime.font = [UIFont fontWithName:kFontNameHelvetica size:14];
    _startTime.backgroundColor = [UIColor clearColor];
    _startTime.textColor = [UIColor colorWithHex:0xff333333];
    [self.contentView addSubview:_startTime];
    [_startTime release];
    
    //到达时间
    _endTime = [[UILabel alloc] initWithFrame:CGRectMake(33, 30, 60, 12)];
    _endTime.font = [UIFont fontWithName:kFontNameHelvetica size:12];
    _endTime.backgroundColor = [UIColor clearColor];
    _endTime.textColor = [UIColor colorWithHex:0xff333333];
    [self.contentView addSubview:_endTime];
    [_endTime release];
    
    
    //出发地址
    _startAddr = [[UILabel alloc] initWithFrame:CGRectMake(128, 8, 100, 14)];
    _startAddr.font = [UIFont fontWithName:kFontNameLightHeiti size:14];
    _startAddr.backgroundColor = [UIColor clearColor];
    _startAddr.textColor = kNormalTextColor;
    [self.contentView addSubview:_startAddr];
    [_startAddr release];
    
    
    //到达地址
    _endAddr = [[UILabel alloc] initWithFrame:CGRectMake(128, 30, 100, 14)];
    _endAddr.font = [UIFont fontWithName:kFontNameHelvetica size:14];
    _endAddr.backgroundColor = [UIColor clearColor];
    _endAddr.textColor = kNormalTextColor;
    [self.contentView addSubview:_endAddr];
    [_endAddr release];
    
    
    //价钱
    _priceLabel = [[UILabel alloc] initWithFrame:CGRectMake(33, 52, 40, 14)];
    _priceLabel.font = [UIFont fontWithName:kFontNameHelvetica size:14];
    _priceLabel.backgroundColor = [UIColor clearColor];
    _priceLabel.textColor = kNormalTextColor;
    _priceLabel.text = @"票价：";
    
    CGSize size = [_priceLabel.text sizeWithFont:_priceLabel.font constrainedToSize:CGSizeMake(200, 20)];
    _priceLabel.frame = CGRectMake(33, 52, size.width, 14);
    
    [self.contentView addSubview:_priceLabel];
    [_priceLabel release];
    
    
    CGFloat originX = CGRectGetMaxX(_priceLabel.frame);
    _priceLabelContent = [[UILabel alloc] initWithFrame:CGRectMake(originX, 52, 70, 14)];
    _priceLabelContent.font = [UIFont fontWithName:kFontNameHelvetica size:14];
    _priceLabelContent.backgroundColor = [UIColor clearColor];
    _priceLabelContent.textColor = kNormalOrangeTextColor;
    [self.contentView addSubview:_priceLabelContent];
    [_priceLabelContent release];
    
    //原始价钱
    _orginPriceLabel = [[UILabel alloc] initWithFrame:CGRectMake(145, 52, 40, 14)];
    _orginPriceLabel.font = [UIFont fontWithName:kFontNameHelvetica size:14];
    _orginPriceLabel.backgroundColor = [UIColor clearColor];
    _orginPriceLabel.textColor = kNormalTextColor;
    _orginPriceLabel.text = @"原价：";
    CGSize originSize = [_orginPriceLabel.text sizeWithFont:_orginPriceLabel.font constrainedToSize:CGSizeMake(200, 20)];
    _orginPriceLabel.frame = CGRectMake(145, 52, originSize.width, 14);
    
    [self.contentView addSubview:_orginPriceLabel];
    [_orginPriceLabel release];
    
    originX = CGRectGetMaxX(_orginPriceLabel.frame);
    
    _orginPriceLabelContent = [[UILabel alloc] initWithFrame:CGRectMake(originX, 52, 60, 14)];
    _orginPriceLabelContent.font = [UIFont fontWithName:kFontNameHelvetica size:14];
    _orginPriceLabelContent.backgroundColor = [UIColor clearColor];
    _orginPriceLabelContent.textColor = kNormalTextColor;
    [self.contentView addSubview:_orginPriceLabelContent];
    [_orginPriceLabelContent release];
    
    UIView *line = [[UIView alloc] initWithFrame:CGRectMake(0, 6, 60, 2)];
    line.backgroundColor  = kNormalTextColor;
    [_orginPriceLabelContent addSubview:line];
    [line release];
    
    
    //燃油费
    _feeLabel = [[UILabel alloc] initWithFrame:CGRectMake(33, 74, 80, 14)];
    _feeLabel.font = [UIFont fontWithName:kFontNameLightHeiti size:14];
    _feeLabel.backgroundColor = [UIColor clearColor];
    _feeLabel.textColor = kNormalTextColor;
    _feeLabel.text = @"机建/燃油：";
    
    originSize = [_feeLabel.text sizeWithFont:_feeLabel.font constrainedToSize:CGSizeMake(200, 20)];
    _feeLabel.frame = CGRectMake(33, 74, originSize.width, 14);
    
    [self.contentView addSubview:_feeLabel];
    [_feeLabel release];
    
    originX = CGRectGetMaxX(_feeLabel.frame);
    _feeLabelContent = [[UILabel alloc] initWithFrame:CGRectMake(originX, 74, 100, 14)];
    _feeLabelContent.font = [UIFont fontWithName:kFontNameHelvetica size:14];
    _feeLabelContent.backgroundColor = [UIColor clearColor];
    _feeLabelContent.textColor = kNormalOrangeTextColor;
    [self.contentView addSubview:_feeLabelContent];
    [_feeLabelContent release];
    
    _lineImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 96, 320, 1)];
    _lineImageView.backgroundColor = [UIColor clearColor];
    [_lineImageView setImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:kLineImageFile ofType:nil]]];
    [self.contentView addSubview:_lineImageView];
    [_lineImageView release];
    
    
}


- (void) bindData:(RCFlyOrderItemInfo *)dataModel{
    if (nil == dataModel) {
        return;
    }
    _startTime.text = dataModel.startTime;
    _endTime.text = dataModel.endTime;
    
    _startAddr.text = dataModel.startAirport;
    _endAddr.text = dataModel.endAirport;
    
    _priceLabelContent.text = [NSString stringWithFormat:@"￥%@",[dataModel.price stringByReplacingOccurrencesOfString:@"￥" withString:@""]];
    
    _orginPriceLabel.hidden = YES;
    _orginPriceLabel.hidden = YES;
    if (![NSString stringIsNullOrEmpty:dataModel.originPrice]) {
        _orginPriceLabel.hidden = NO;
        _orginPriceLabel.hidden = NO;
         _orginPriceLabelContent.text = [NSString stringWithFormat:@"￥%@",[dataModel.originPrice stringByReplacingOccurrencesOfString:@"￥" withString:@""]];
    }
   
    
    _feeLabelContent.text = [NSString stringWithFormat:@"￥%@/￥%@",[dataModel.airportFee stringByReplacingOccurrencesOfString:@"￥" withString:@""],[dataModel.fuelFee stringByReplacingOccurrencesOfString:@"￥" withString:@""]];
    
}

+ (CGFloat)getCellHeight{
    return 97.0f;
}




@end


@implementation RCTicketFlySeatTypeCell{
    UILabel *_leftLabel;
    UILabel *_rigthLabel;
    UIImageView *_arrowImageView;
    UIImageView *_lineImageView;
    
    
}

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
        UIImage *bgImage = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:kBGImageFile ofType:nil]];
        [self setBackgroundColorWithImage:bgImage];
        self.backgroundColor = [UIColor clearColor];
        
        [self createPlaceHolder];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return self;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

- (void) createPlaceHolder
{
    
    _leftLabel = [[UILabel alloc] initWithFrame:CGRectMake(33, 12, 100, 14)];
    _leftLabel.font = [UIFont fontWithName:kFontNameLightHeiti size:14];
    _leftLabel.backgroundColor = [UIColor clearColor];
    _leftLabel.textColor = kNormalTextColor;
    _leftLabel.text = @"修改舱位";
    [self.contentView addSubview:_leftLabel];
    [_leftLabel release];
    
    _rigthLabel = [[UILabel alloc] initWithFrame:CGRectMake(140, 12, 150, 14)];
    _rigthLabel.font = [UIFont fontWithName:kFontNameLightHeiti size:14];
    _rigthLabel.backgroundColor = [UIColor clearColor];
    _rigthLabel.textAlignment = UITextAlignmentRight;
    _rigthLabel.textColor = [UIColor colorWithHex:0xff0e5eb7];
    [self.contentView addSubview:_rigthLabel];
    [_rigthLabel release];
    
    _arrowImageView = [[UIImageView alloc]initWithFrame:CGRectMake(296, 13, 10, 12)];
    _arrowImageView.backgroundColor = [UIColor clearColor];
    [_arrowImageView setImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:kArrowImageFile ofType:nil]]];
    [self.contentView addSubview:_arrowImageView];
    [_arrowImageView release];
    
    _lineImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 37, 320, 1)];
    _lineImageView.backgroundColor = [UIColor clearColor];
    [_lineImageView setImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:kLineImageFile ofType:nil]]];
    [self.contentView addSubview:_lineImageView];
    [_lineImageView release];
}

- (void) bindData:(RCFlyOrderItemInfo*)dataModel
{
    if (nil == dataModel) {
        return;
    }
    _rigthLabel.text = dataModel.flyType;
}

+(CGFloat)getCellHeight{
    return 38;
}


@end



@implementation RCTicketFlyAddUserInfoCell{
    UILabel *_leftLabel;
    UIImageView            *_addUserImageView;
    UILabel     *_addUserCodeLabel;
    UIImageView *_lineImageView;
}

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
        UIImage *bgImage = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:kBGImageFile ofType:nil]];
        [self setBackgroundColorWithImage:bgImage];
        self.backgroundColor = [UIColor clearColor];
        
        [self createPlaceHolder];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return self;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

- (void) createPlaceHolder
{
    UIImageView *leftIMG = [[UIImageView alloc] initWithFrame:CGRectMake(33, 15, 7, 8)];
    [self.contentView addSubview:leftIMG];
    leftIMG.image = [UIImage imageNamed:@"icon_ticketOrder_star"];
    [leftIMG release];
    
    _leftLabel = [[UILabel alloc] initWithFrame:CGRectMake(46, 12, 200, 14)];
    _leftLabel.font = [UIFont fontWithName:kFontNameLightHeiti size:14];
    _leftLabel.backgroundColor = [UIColor clearColor];
    _leftLabel.textColor = kNormalTextColor;
    _leftLabel.text = @"登机人";
    [self.contentView addSubview:_leftLabel];
    [_leftLabel release];
    
    _addUserImageView = [[UIImageView alloc]initWithFrame:CGRectMake(214, 5, 92, 28)];
    _addUserImageView.backgroundColor = [UIColor clearColor];
    [_addUserImageView setImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"flyTicket_formBG_flylabel_down.png" ofType:nil]]];
    
    UIImageView *addIcon = [[UIImageView alloc]initWithFrame:CGRectMake(2, 9, 10, 10)];
    addIcon.backgroundColor = [UIColor clearColor];
    [addIcon setImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"flyTicket_orderCell_addUser.png" ofType:nil]]];
    [_addUserImageView addSubview:addIcon];
    [addIcon release];
    
    _addUserCodeLabel = [[UILabel alloc]initWithFrame:CGRectMake(14, 7, 77, 14)];
    _addUserCodeLabel.backgroundColor = [UIColor clearColor];
    _addUserCodeLabel.font = [UIFont fontWithName:kFontNameLightHeiti size:14];
    _addUserCodeLabel.textColor = kNormalTextColor;
    _addUserCodeLabel.text = @"添加登机人";
    [_addUserImageView addSubview:_addUserCodeLabel];
    [_addUserCodeLabel release];
    
    [self.contentView addSubview:_addUserImageView];
    [_addUserImageView release];
    
    _lineImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 37, 320, 1)];
    _lineImageView.backgroundColor = [UIColor clearColor];
    [_lineImageView setImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:kLineImageFile ofType:nil]]];
    [self.contentView addSubview:_lineImageView];
    [_lineImageView release];
    
}

+(CGFloat)getCellHeight{
    return 38;
}



@end





@implementation RCTicketFlyTotalPriceCell{
    
    UILabel *_leftLabel;
    UILabel *_rightLabel;
    UIButton *_orderButton;
    
}

@synthesize delegate = _delegate;

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
        self.backgroundColor = [UIColor clearColor];
        [self createPlaceHolder];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return self;
}

-(void)dealloc{
    self.delegate = nil;
    [super dealloc];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

- (void) createPlaceHolder
{
    _orderButton = [[UIButton alloc]initWithFrame:CGRectMake(14, 50, 292, 36)];
    _orderButton.backgroundColor = [UIColor clearColor];
    UIImage *orderImage = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"bg_ticketOrder_total.png" ofType:nil]];
    [_orderButton setBackgroundImage:orderImage forState:UIControlStateNormal];
    [_orderButton setBackgroundImage:orderImage forState:UIControlStateHighlighted];
    [_orderButton addTarget:self action:@selector(orderButtonClicked) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:_orderButton];
    [_orderButton release];
    
    _leftLabel = [[UILabel alloc] initWithFrame:CGRectMake(33, 61, 200, 14)];
    _leftLabel.font = [UIFont fontWithName:kFontNameHelvetica size:14];
    _leftLabel.backgroundColor = [UIColor clearColor];
    _leftLabel.textColor = [UIColor whiteColor];
    [self.contentView addSubview:_leftLabel];
    [_leftLabel release];
    
    
    
    _rightLabel = [[UILabel alloc] initWithFrame:CGRectMake(260, 61, 40, 14)];
    _rightLabel.font = [UIFont fontWithName:kFontNameHelvetica size:14];
    _rightLabel.backgroundColor = [UIColor clearColor];
    _rightLabel.textColor = [UIColor whiteColor];
    _rightLabel.text = @"预订";
    [self.contentView addSubview:_rightLabel];
    [_rightLabel release];
    
}

+(CGFloat)getCellHeight{
    return 96;
}

- (void) bindData:(RCFlyOrderItemInfo *)dataModel
{
    
    if (nil == dataModel) {
        return;
    }
    NSInteger price = [dataModel.price intValue] + [dataModel.airportFee intValue] + [dataModel.fuelFee intValue];
    _leftLabel.text = [NSString stringWithFormat:@"订单总额 ￥%d",price];
    
}

-(void)orderButtonClicked{
    if (_delegate && [_delegate respondsToSelector:@selector(commitOrderButtonClick)]) {
        [_delegate commitOrderButtonClick];
    }
}


@end
